import { http } from '@/utils'

// 获取频道列表
export const getChannels = (params) => {
  return async (dispatch) => {
    const res = await http.get('/channels', params)

    dispatch({ type: 'article/getChannels', payload: res.data.data })
  }
}

// 获取文章列表
export const getArticle = (params) => {
  return async (dispatch) => {
    const res = await http.get('/mp/articles', { params })

    const {
      page,
      per_page: pageSize,
      results: list,
      total_count: count,
    } = res.data.data
    dispatch({
      type: 'articlt/getArticle',
      payload: {
        page,
        pageSize,
        count,
        list: list.map((item) => {
          return {
            ...item,
            cover: item.cover.images[0],
          }
        }),
      },
    })
  }
}

/**
 * 删除文章列表
 * id
 */
export const delclickDel = (id) => {
  return async () => {
    const res = await http.delete(`/mp/articles/${id}`)
    console.log(res)
  }
}
